<?php

namespace App\Http\Requests\Admin\AdminUser;

use App\Http\Requests\Request;

class UpdateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     *
     * @return array
     */
    public function rules()
    {
        $rules =  [
            'password' => 'required|confirmed:re_password',
            'role_id'=>'required|exists:admin_role,id'
        ];

        if ($this->request->get('password')==''){
            unset($rules['password']);
        }

        return $rules;

    }

    /**
     * 验证信息
     * @return array
     */

    public function messages()
    {
        return [
            'password.required'  => '请填写密码',
            'password.confirmed'  => '两次输入密码不一致',
            'role_id.required'=>'请选择用户组',
            'role_id.exists'=>'用户组不存在'
        ];
    }
}
